<script setup>

import {defineProps, reactive} from "vue";
import {reviewResult, updateResult} from "@/api/api";
import {message} from "ant-design-vue";

const props = defineProps({
  data: Object,
  role: Number
})

const information = reactive({
  ProjectName: props.data.info.ProjectName,
  ContractNumber: props.data.info.ContractNumber,
  TotalContractAmount: props.data.info.TotalContractAmount,
  ClientOrganizationName: props.data.info.ClientOrganizationName,
  ProjectManager: props.data.info.ProjectManager,
  ExecutionDirector: props.data.info.ExecutionDirector,
  ProjectDuration: props.data.info.ProjectDuration,
  PaymentRecords:props.data.info.PaymentRecords,
  Participants: props.data.info.Participants,
  FinancialAccount: props.data.info.FinancialAccount,
  PaymentReceipts: props.data.info.PaymentReceipts,
  ProjectClosureDate: props.data.info.ProjectClosureDate,
  ClosureCertificate: props.data.info.ClosureCertificate,
  ClosureReport: props.data.info.ClosureReport,
  SubmissionDate: props.data.info.SubmissionDate,
  msg: ''
})

const postData = reactive({
  id: props.data.id,
  master: props.data.master,
  review: props.data.review,
})

const reviewed = (sta) => {
  console.log(sta)
  const resdata = {
    id: postData.id,
    master: postData.master,
    review: sta,
    info: {
      ProjectName: information.ProjectName,
      ContractNumber: information.ContractNumber,
      TotalContractAmount: information.TotalContractAmount,
      ClientOrganizationName: information.ClientOrganizationName,
      ProjectManager: information.ProjectManager,
      ExecutionDirector: information.ExecutionDirector,
      ProjectDuration: information.ProjectDuration,
      PaymentRecords:information.PaymentRecords,
      Participants: information.Participants,
      FinancialAccount: information.FinancialAccount,
      PaymentReceipts: information.PaymentReceipts,
      ProjectClosureDate: information.ProjectClosureDate,
      ClosureCertificate: information.ClosureCertificate,
      ClosureReport: information.ClosureReport,
      SubmissionDate: information.SubmissionDate,
      msg: information.msg
    }
  }
  console.log(123)
  console.log(resdata)
  reviewResult(resdata).then((res) => {
    console.log(res.data)
    location.reload()
  })
}

const update = () => {
  const resdata = {
    id: postData.id,
    master: postData.master,
    review: 0,
    info: {
      ProjectName: information.ProjectName,
      ContractNumber: information.ContractNumber,
      TotalContractAmount: information.TotalContractAmount,
      ClientOrganizationName: information.ClientOrganizationName,
      ProjectManager: information.ProjectManager,
      ExecutionDirector: information.ExecutionDirector,
      ProjectDuration: information.ProjectDuration,
      PaymentRecords:information.PaymentRecords,
      Participants: information.Participants,
      FinancialAccount: information.FinancialAccount,
      PaymentReceipts: information.PaymentReceipts,
      ProjectClosureDate: information.ProjectClosureDate,
      ClosureCertificate: information.ClosureCertificate,
      ClosureReport: information.ClosureReport,
      SubmissionDate: information.SubmissionDate,
      msg: information.msg
    }
  }
  console.log(123)
  console.log(resdata)
  updateResult(resdata).then((res) => {
    console.log(res.data)
    if(res.data.status !== 200){
      message.warn(res.data.msg)
    }else{
      location.reload()
    }
    // location.reload()
  })
}

</script>

<template>
<div>
  <div v-if="role === 2">
    <div>项目名称: </div>
    <a-input :disabled="true" v-model:value="information.ProjectName" :placeholder="information.ProjectName" />
    <div>合同号: </div>
    <a-input :disabled="true" v-model:value="information.ContractNumber" :placeholder="information.ContractNumber" />
    <div>合同总金额: </div>
    <a-input :disabled="true" v-model:value="information.TotalContractAmount" :placeholder="information.TotalContractAmount" />
    <div>甲方单位名称: </div>
    <a-input :disabled="true" v-model:value="information.ClientOrganizationName" :placeholder="information.ClientOrganizationName" />
    <div>项目负责人: </div>
    <a-input :disabled="true" v-model:value="information.ProjectManager" :placeholder="information.ProjectManager" />
    <div>执行负责人: </div>
    <a-input :disabled="true" v-model:value="information.ExecutionDirector" :placeholder="information.ExecutionDirector" />
    <div>期限: </div>
    <a-input :disabled="true" v-model:value="information.ProjectDuration" :placeholder="information.ProjectDuration" />
    <div>到款记录: </div>
    <a-input :disabled="true" v-model:value="information.PaymentRecords" :placeholder="information.PaymentRecords" />
    <div>参与人: </div>
    <a-input :disabled="true" v-model:value="information.Participants" :placeholder="information.Participants" />
    <div>财务账号: </div>
    <a-input :disabled="true" v-model:value="information.FinancialAccount" :placeholder="information.FinancialAccount" />
    <div>到款凭证: </div>
    <a-input :disabled="true" v-model:value="information.PaymentReceipts" :placeholder="information.PaymentReceipts" />
    <div>结题时间: </div>
    <a-input :disabled="true" v-model:value="information.ProjectClosureDate" :placeholder="information.ProjectClosureDate" />
    <div>结题证明: </div>
    <a-input :disabled="true" v-model:value="information.ClosureCertificate" :placeholder="information.ClosureCertificate" />
    <div>结题报告: </div>
    <a-input :disabled="true" v-model:value="information.ClosureReport" :placeholder="information.ClosureReport" />
    <div>填报日期: </div>
    <a-input :disabled="true" v-model:value="information.SubmissionDate" :placeholder="information.SubmissionDate" />
    <div>指导教师编号: </div>
    <a-input :disabled="true" v-model:value="postData.master" :placeholder="postData.master" />
    <div>评价：</div>
    <a-textarea v-model:value="information.msg">
    </a-textarea>
    <div>
      <a-button @click="reviewed(1)">通过</a-button>
      <a-button @click="reviewed(-1)">拒绝</a-button>
    </div>
  </div>

  <div v-if="role === 3">
    <div>项目名称: </div>
    <a-input :disabled="false" v-model:value="information.ProjectName" :placeholder="information.ProjectName" />
    <div>合同号: </div>
    <a-input :disabled="false" v-model:value="information.ContractNumber" :placeholder="information.ContractNumber" />
    <div>合同总金额: </div>
    <a-input :disabled="false" v-model:value="information.TotalContractAmount" :placeholder="information.TotalContractAmount" />
    <div>甲方单位名称: </div>
    <a-input :disabled="false" v-model:value="information.ClientOrganizationName" :placeholder="information.ClientOrganizationName" />
    <div>项目负责人: </div>
    <a-input :disabled="false" v-model:value="information.ProjectManager" :placeholder="information.ProjectManager" />
    <div>执行负责人: </div>
    <a-input :disabled="false" v-model:value="information.ExecutionDirector" :placeholder="information.ExecutionDirector" />
    <div>期限: </div>
    <a-input :disabled="false" v-model:value="information.ProjectDuration" :placeholder="information.ProjectDuration" />
    <div>到款记录: </div>
    <a-input :disabled="false" v-model:value="information.PaymentRecords" :placeholder="information.PaymentRecords" />
    <div>参与人: </div>
    <a-input :disabled="false" v-model:value="information.Participants" :placeholder="information.Participants" />
    <div>财务账号: </div>
    <a-input :disabled="false" v-model:value="information.FinancialAccount" :placeholder="information.FinancialAccount" />
    <div>到款凭证: </div>
    <a-input :disabled="false" v-model:value="information.PaymentReceipts" :placeholder="information.PaymentReceipts" />
    <div>结题时间: </div>
    <a-input :disabled="false" v-model:value="information.ProjectClosureDate" :placeholder="information.ProjectClosureDate" />
    <div>结题证明: </div>
    <a-input :disabled="false" v-model:value="information.ClosureCertificate" :placeholder="information.ClosureCertificate" />
    <div>结题报告: </div>
    <a-input :disabled="false" v-model:value="information.ClosureReport" :placeholder="information.ClosureReport" />
    <div>填报日期: </div>
    <a-input :disabled="false" v-model:value="information.SubmissionDate" :placeholder="information.SubmissionDate" />
    <div>指导教师编号: </div>
    <a-input :disabled="false" v-model:value="postData.master" :placeholder="postData.master" />
    <div>
      <a-button @click="update">
        Update
      </a-button>
    </div>
  </div>
</div>
</template>

<style scoped>
div{
  margin-top: 1rem;
}
</style>